package package1;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class h {

	public static void main(String[] args) throws IOException {
//		makeNestingFolders();
//		deleteFolderContent("");
		
		
	}
	
	public static void makeNestingFolders() throws IOException {
		String filePath = ".";//. = current folder
		String folderStr = "c.d.e";
		for(String fname:folderStr.split("\\.")) new File(filePath += "\\"+fname).mkdirs();
		openCurrentFolder();
	}
	
	public static void openCurrentFolder() throws IOException {
		open(getCurrentFolder());
	}
	
	private static void deleteFolderContent(String f) throws IOException {
		File folder = new File(f);
		if(folder.isFile())throw new IOException(f+" is not a folder, it is a file");
		else doDeleteFolderContent(folder);
	}
	private static void deleteFolderContent(File folder) throws IOException {
		if(folder.isDirectory())doDeleteFolderContent(folder);
		else throw new IOException(folder.getName()+" is not a folder, it is a file");
	}
	
	private static void doDeleteFolderContent(File folder) throws IOException {
		for(File file:folder.listFiles()){
			if(file.isDirectory())doDeleteFolder(file);
			else file.delete();
		}
	}
	private static void doDeleteFolder(File folder) {
		for(File file:folder.listFiles()) if(file.isDirectory()) doDeleteFolder(file);else file.delete(); 
		folder.delete();
	}
	
	private static String getCurrentFolder() {
		return System.getProperty("user.dir");
	}
	
	private static void open(String f1) throws IOException {
		open(new File(f1));
	}
	private static void open(File file) throws IOException {
		java.awt.Desktop.getDesktop().open(file);
	}

	private static String getDesktop() {
		return System.getenv("USERPROFILE") + "\\desktop";
	}

}
